TemplateReporter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 18
dl 0
loc 29
rs 10
c 0
b 0
f 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A constructor 0 5 1
A _init 0 5 1
A _generate 0 7 1
A write 0 7 1
1
import fs from 'fs-extra';
2
import handleBars from '../handlebars';
3
import Base from  './Base';
4
5
export default class TemplateReporter extends Base {
6
    constructor(file, { path, templateOpts = {} } = {}) {
7
        super(file);
8
        this.templatePath = path;
9
        this.templateOpts = templateOpts;
10
    }
11
12
    _generate(groups, map) {
13
        return this._template({
14
            groups,
15
            actions : map,
16
            options : this.templateOpts
17
        });
18
    }
19
20
    async _init() {
21
        const templateContent = await fs.readFile(this.templatePath);
22
23
        this._template = handleBars.compile(templateContent.toString(), { preventIndent: true });
24
    }
25
26
    async write(actions) {
27
        await this._init();
28
        const { groups, map } = this._build(actions, { groupBy: [ 'context.group', 'context.title' ] });
29
        const content = this._generate(groups, map, actions);
30
31
        await fs.writeFile(this.file, content);
32
    }
33
}
34